package sentinel;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;

/**
 * @Auther: 肖冬
 * @Date: 2020/8/18 21:37
 * @Description:
 */
public class SentinelTest {

    public static void main(String[] args) {
        Config config = new Config();
        config.setCodec(new StringCodec());

        //指定使用哨兵部署方式
        config.useSentinelServers()
        .setMasterName("redis-master")
        .addSentinelAddress("redis://192.168.1.21:6379")
        .addSentinelAddress("redis://192.168.1.21:6380")
        .addSentinelAddress("redis://192.168.1.21:6380");

        RedissonClient redisson = Redisson.create(config);
        //首先获取redis中的key-value对象，key不存在没关系
        RBucket<String> keyObject = redisson.getBucket("redisson-sitinel-key");
        //如果key存在，就设置key的值为新值value
        //如果key不存在，就设置key的值为value
        keyObject.set("value");

        //最后关闭RedissonClient
        redisson.shutdown();
    }
}
